package PIPL::System::EnvTest;

use strict;

use base 'Test::Unit::TestCase';

use PIPL::System::Env;

sub new {
    my $self = shift()->SUPER::new(@_);
    return $self;
}

sub test_PIPL_System_Env_new {
    my $self = shift;
    my $obj1 = PIPL::System::Env->new;
    $self->assert_not_null($obj1);
    $self->assert($obj1->isa('PIPL::System::Env'));
    my $obj2 = $obj1->new;
    $self->assert_not_null($obj2);
    $self->assert($obj2->isa('PIPL::System::Env'));
}

sub test_PIPL_System_Env_instance {
    my $self = shift;
    PIPL::System::Env->destroy;
    my $obj1 = PIPL::System::Env->instance;
    my $obj2 = PIPL::System::Env->instance;
    $self->assert_not_null($obj1);
    $self->assert_not_null($obj2);
    $self->assert($obj1->isa('PIPL::System::Env'));
    $self->assert($obj2->isa('PIPL::System::Env'));
    $self->assert_equals($obj1, $obj2);
}

sub test_PIPL_System_Env_Self {
    my $self = shift;
    my $value1 = '1:' . time;
    my $value2 = '2:' . time;
    $ENV{'PERL_PIPL_SYSTEM_ENV_TEST1'} = $value1;
    $self->assert($value1, $ENV{'PERL_PIPL_SYSTEM_ENV_TEST1'});
    $self->assert_equals($value1, $PIPL::System::Env::Self->{'PERL_PIPL_SYSTEM_ENV_TEST1'});
    $PIPL::System::Env::Self->{'PERL_PIPL_SYSTEM_ENV_TEST2'} = $value2;
    $self->assert($value2, $ENV{'PERL_PIPL_SYSTEM_ENV_TEST2'});
    $self->assert_equals($value2, $PIPL::System::Env::Self->{'PERL_PIPL_SYSTEM_ENV_TEST2'});
    my $obj = PIPL::System::Env->instance;
    $self->assert_not_null($obj);
    $self->assert($obj->isa('PIPL::System::Env'));
    $self->assert_equals($value1, $obj->{'PERL_PIPL_SYSTEM_ENV_TEST1'});
    $self->assert_equals($value2, $obj->{'PERL_PIPL_SYSTEM_ENV_TEST2'});
}

1;
